/**
 * @description 地址
 * @param {string} path
 * @returns {Boolean}
 */
export const isExternal = (path) => {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @description 登陆用户名
 * @param {string} str
 * @returns {Boolean}
 */
export const validUsername = (str) => {
  const valid_map = ['admin', 'editor', 'visitor']
  return valid_map.indexOf(str.trim()) >= 0
}

/**
 * @description 地址
 * @param {string} url
 * @returns {Boolean}
 */
export const validURL = (url) => {
  const reg =
    /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
  return reg.test(url)
}

/**
 * @description 小写
 * @param {string} str
 * @returns {Boolean}
 */
export const validLowerCase = (str) => {
  const reg = /^[a-z]+$/
  return reg.test(str)
}

/**
 * @description 大写
 * @param {string} str
 * @returns {Boolean}
 */
export const validUpperCase = (str) => {
  const reg = /^[A-Z]+$/
  return reg.test(str)
}

/**
 * @description 字母
 * @param {string} str
 * @returns {Boolean}
 */
export const validAlphabets = (str) => {
  const reg = /^[A-Za-z]+$/
  return reg.test(str)
}

/**
 * @description 邮箱
 * @param {string} email
 * @returns {Boolean}
 */
export const validEmail = (email) => {
  const reg =
    /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  return reg.test(email)
}

/**
 * @description 是否为手机号
 * @param {*} val
 * @returns
 */
export const isMobile = (val) => {
  return /^1[3456789]\d{9}$/.test(val)
}

/**
 * @description 是否为身份证
 * @param {*} val
 * @returns
 */
export const isSFID = (val) => {
  return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(val)
}

/**
 * @description 是否为邮箱
 * @param {*} val
 * @returns
 */
export const isEmail = (val) => {
  return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(val)
}

/**
 * @description 是否为固定电话
 * @param {*} val
 * @returns
 */
export const isLandline = (val) => {
  return /^(([0+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(val)
}
